<?php

/* @var $this \yii\web\View */
/* @var $content string */

use yii\helpers\Html;
use yii\helpers\Url;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use frontend\assets\AppAsset;
use yii\widgets\ActiveForm;
use frontend\models\register\RegisterForm;
use frontend\models\login\LoginForm;
use frontend\models\search\Search;
use common\widgets\Alert;
use backend\models\system\SysConfig;

$register = new RegisterForm();
$login = new LoginForm();

AppAsset::register($this);

?>
<meta property="qc:admins" content="25233160436270006375" />
<?php 
$this->beginPage() 
?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">


	<meta name="keywords" content="<?= Html::encode(Yii::$app->params['sysconfig']["'BASIC_INFORMATION'"]["'KEYWORDS'"])?>">
	<meta name="description" content="<?= Html::encode(Yii::$app->params['sysconfig']["'BASIC_INFORMATION'"]["'DESCRIPTION'"])?>">


    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode(Yii::$app->params['sysconfig']["'BASIC_INFORMATION'"]["'SITENAME'"])?></title>
    <?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<script type="text/javascript" src="/assets/js/MogFocus.js"></script>
<div class="microoh-main">
    <header class="navbar navbar-default navbar-fixed-top" data-spy="affix" data-offset-top="64">
        <div class="container">
            <div class="navbar-header" style="padding-right: 10px;">
                <a class="" href="<?= Url::to(['site/index']); ?>" title="logo">
                
                <img src="http://admin.bwphp.com/<?= Html::encode(Yii::$app->params['sysconfig']["'BASIC_INFORMATION'"]["'LOGO'"])?>" width="120px;" height="60px">
                
                </a>
            </div>
            <style type="text/css">
                .active-nav{
                    background-color: #333333;
                }
            </style>
            <div class="collapse navbar-collapse" id="microoh-navbar-collapse">
                <ul class="nav navbar-nav navbar-left">
	                <?php

	                if($this->context->id == "site")
	                {
		        ?>
		                <li class="active-nav"><a href="<?= Url::to(['site/index']); ?>">首页</a></li>
		        <?php
	                }
	                else
	                {
		        ?>
		                <li><a href="<?= Url::to(['site/index']); ?>">首页</a></li>
		        <?php }
		                /* 网站导航 */
		                $web_nav = Yii::$app->params['sysconfig']["'TOP_NAV'"];
		                foreach($web_nav as $k=>$v){
			                $web_nav[$k] = unserialize($v);
		                }
	                    foreach($web_nav as $k=>$v){
		                    if($v['nav_status'] == 1){
		                    if(strstr($v['nav_url'],$this->context->id))
		                    {
	                ?>
			                    <li class="active-nav"><a href="<?= Url::to([$v['nav_url']]); ?>"><?= Html::encode($v['nav_name'])?></a></li>
			                <?php } else { ?>
			                    <li><a href="<?= Url::to([$v['nav_url']]); ?>"><?= Html::encode($v['nav_name'])?></a></li>
	                <?php }}} ?>

                </ul>
                <style type="text/css">
                .nav #keywords{
                    width:200px;
                    display:inline-block;
                    border:1px solid #69f;
                    color:#B1CFD9;
                    padding-left: 8px;
                }
                #keywords::-webkit-input-placeholder {color: #B1CFD9;}
                #keywords:-moz-placeholder {color: #B1CFD9;}
                #keywords::-moz-placeholder {color: #B1CFD9;}
                #keywords:-ms-placeholder {color: #B1CFD9;}
                </style>
                <!--搜索-->
	            <?php
	                if($Search = Yii::$app->request->get("Search")){
		                $search_content = $Search['search_content'];
	                }
	                else
	                {
		                $search_content = "";
	                }
	            ?>
	            <div class="nav navbar-nav navbar-left" style="padding:15px 15px 0px 15px;">
		            <?php
		            $search = new Search();
		            $form = ActiveForm::begin([
			            'action'=>Url::to(['site/search']),
			            'method'=>'get',
                        'id' => 'search-form',
			            'fieldConfig' => [
				            'template' => '{input}{error}'
			            ],
		            ]);
		            ?>
                    <style type="text/css">
                        #search-form .form-group {
                            display: inline-block;
                            margin-bottom: 0px;
                        }
                    </style>
		            <?= $form->field($search, 'search_content',['inputOptions'=>['placeholder'=>'请输入搜索关键字']])->textInput(['maxlength' => 60,'id'=>'keywords','class'=>'form-control','value'=>$search_content]) ?>
		            <?= Html::submitButton('搜索', ['class'=>'btn btn-micv5','style' =>'width:80px;']) ?>
		            <?php ActiveForm::end();?>
	            </div>


                <div class="v5-topbar-login">
				<?php
					$session = Yii::$app->session;
					$session->open();
					if($session->get('user_id')){
				?>
					 <div class="v5-topbar-login-off">
						<a href="<?= Url::to(['center/index'])?>">个人中心</a>&nbsp;&nbsp;&nbsp;
						<a href="javascript:void(0)" id='loginout'>退出</a>
                    </div>
				<?php }else{?>
                    <div class="v5-topbar-login-off">
                        <a onclick="register_popup()">注册</a>&nbsp;&nbsp;&nbsp;
                        <a onclick="login_popup()" id='login_popup'>登录</a>
                    </div>
				<?php }?>
                </div>
            </div>
            
        </div>
    </header>
    <?= Alert::widget() ?>
    <?= $content ?>

	<style>
		#goTopBtn {position: fixed;line-height:36px;width:36px;bottom:35px;height:36px;cursor:pointer;display:none;
			background:#0000CC;}
	</style>

<div class="v5-footer">
    <div class="container">
        <div class="v5-footer-bottom">
            <p style="line-height: 26px"><a href="http://www.bwphp.com/"><?= Html::encode(Yii::$app->params['sysconfig']["'BASIC_INFORMATION'"]["'COPYRIGHT'"])?></a></p>
            <p style="line-height: 26px"><?= Html::encode(Yii::$app->params['sysconfig']["'BASIC_INFORMATION'"]["'ICP'"])?></p>
        </div>
    </div>
  </div>
</div>
<div class="toolbar">

    <a class="toolbar-item toolbar-item-gotop" id="goTopBtn" style="background-color: transparent" ><img src="/static/images/backtop1.png" alt="返回顶部"><span>返回顶部</span></a>
</div>
<!--不能重复喜欢弹框-->
<div class="modal fade" id="loginOut" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm" style="top:150px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" style="font-size: 18px;">消息提示</h4>
            </div>
            <div class="modal-body">
                <section class="box-login v5-input-txt" id="box-login">
                        <center><h4 style="font-size: 18px;margin-bottom: 20px;">确定退出？</h4>
                        <button data-dismiss="modal"  style="width: 150px;" type="button" class="btn btn-micv5 btn-block">取消</button>&nbsp;&nbsp;<button   style="width: 150px;" type="button" id="doOut" class="btn btn-micv5 btn-block">确定</button></center>
						
                </section>
            </div>
        </div>
    </div>
</div>

<!--弹出层区块-->

<!--找回密码-->
<div class="modal fade" id="forgetpswModal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" data-toggle="modal" data-target="#loginModal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="forgetpswModalLabel" style="font-size: 18px;">找回密码</h4>
            </div>
            <div class="modal-body">
                <section class="box-forgetpsw v5-input-txt" id="box-forgetpsw">
                    <form id="find_password_form" action="/user/password/find/" method="post" autocomplete="off">
                        
                        <ul>
                            <li class="form-group"><input class="form-control" id="forgetpwd" maxlength="50" name="account" placeholder="请输入注册邮箱账号或手机号码" type="text"></li>
                            


                            <li class="form-group field-registerform-user_code required">
                            <div class="form-group cf"><input  class="form-control form-control-phone fl" id='phone' name="" placeholder="请输入验证码" type="text"><span class="send-code fr"><button  type="button" class="btn btn-micv5 btn-send" id="fcode" >发送验证码</button></span></div><font color='red'><span id='pcode'></span></font><div class="help-block"></div>
                            </li>
                            <li class="form-group">&nbsp;</li>
                        </ul>
                        <div>
                           <button id="next" type="button" class="btn btn-block" onclick="reset_popup();" disabled>下一步</button>
                        </div>
                        <div id="findpassword-tips" class="tips-error bg-danger">错误提示</div>
                    </form>
                </section>
            </div>
        </div>
    </div>
</div>


<!--忘记密码输入重复密码-->
<div class="modal fade" id="resetpwsModal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="loginModalLabel" style="font-size: 18px;">找回密码</h4>
            </div>
            <div class="modal-body">
                <section class="box-login v5-input-txt" id="box-login">
                    <form id="mobile_code_password_form" action="/user/password/find/mobile/" method="post" autocomplete="off">
                        
                        <ul>
                            <li class="form-group"><input class="form-control" id='newpwd' name="" placeholder="请输入新密码" type="password"><font color='red'><span id='usernewpwd'></span></font></li>

                            <li class="form-group"><input class="form-control" id='rightnewpwd' name="" placeholder="请输入确认密码" type="password"><font color='red'><span id='qnewpwd'></span></font></li>
                        </ul>
                        <div>
                            <button id="save_pwd" type="button" class="btn btn-micv5 btn-block" onclick="" disabled>确认</button>
                        </div>
                    </form>
                </section>
            </div>
        </div>
    </div>
</div>



<!--登录-->
<div class="modal fade" id="loginModal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="loginModalLabel" style="font-size: 18px;">登录</h4>
            </div>
            <div class="modal-body">
                <section class="box-login v5-input-txt" id="box-login">
                      <?php $form = ActiveForm::begin([
                        'action' =>\Yii::$app->urlManager->createUrl('index/login'),
                        'method'=>'post',
                        'id' => $login->formName(),
                      
                      ]); ?>  
                        <ul>

                        <!--用户名-->
                        <?= $form->field($login, 'user_name', 
                        [
                            'inputOptions' => ['placeholder'=>'请输入邮箱账号/手机号', 'class' => 'form-control'],
                            'template' => '<li class="form-group">{input}</li>{error}',
                        ])->textInput() 
                        ?>

                        <!--密码-->
                        <?= $form->field($login, 'user_pwd', 
                        [
                            'inputOptions' => ['placeholder'=>'请输入密码', 'class' => 'form-control'],
                            'template' => '<li class="form-group">{input}</li>{error}',
                        ])->passwordInput() 
                        ?>
                            
                        </ul>
                        <div id="login-form-notice" style="color: red" class="help-block"></div>
						<?= $form->field($login, 'rememberMe')->checkbox() ?>
                    <p class="good-tips"><a href="#" data-toggle="modal" data-target="#forgetpswModal" id="btnForgetpsw" class="fr">忘记密码？</a>还没有账号？<a phptag="phptag_register" href="" data-toggle="modal" data-target="#registerModal" id="btnRegister">立即注册</a></p>
                    <div>
						<?= Html::submitButton('登录', ['class' => 'btn btn-micv5 btn-block','id'=>'loginbtn']) ?>
                    </div><?php ActiveForm::end(); ?>
                    
                    
                    <div class="threeLogin"><span>其他方式登录</span><a class="nqq" href="<?= Url::to(['site/auth'])?>?authclient=qq"><img src="/assets/img/qq.jpg" width="20"/></a><a class="nwx" href="http://www.bwphp.com/user/connect/?partner=wechat"><img src="/assets/img/weixin.jpg" width="20"/></a><a href="<?php if(isset($code_url)){
					echo $code_url;
					} ?>" title="新浪微博登录"><img src="/assets/img/weibo.png" width="20"/></a></div>
                    
                </section>
            </div>
        </div>
    </div>
</div>


<?php
$login_url = Url::to(['index/login']);
$js = <<<JS

$('form#{$login->formName()}').on('beforeSubmit', function(e) {
    $('#login-form-notice').text('');
    var user_name = $('#loginform-user_name').val();
    var user_pwd = $('#loginform-user_pwd').val();
    var remember = $('#loginform-rememberme').val();
    var _csrf = $('input[name=_csrf]').val();
    $.post('{$login_url}', {
        'LoginForm[user_name]' : user_name,
        'LoginForm[user_pwd]' : user_pwd,
        '[LoginForm[rememberMe]' : remember,
        '_csrf' : _csrf
    }, function(data){

        if (data.code == 400) {
            $('#login-form-notice').text(data.msg);
        } else if (data.code == 200){
            history.go(0);
        }
    });
}).on('submit', function(e){
    e.preventDefault();
});
JS;
$this->registerJs($js);
?>

<!--注册-->
<div class="modal fade" id="registerModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-md">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="registerModalLabel" style="font-size: 18px;">注册</h4>
            </div>
            <div class="modal-body">
                <section class="box-register v5-input-txt" id="box-register">
                    <div class="tab-content">
                        <div class="tab-pane active" id="register-mobile">
                            <?php $form = ActiveForm::begin([
                                'action' =>Url::to(['index/register']),
                                'method'=>'post',
                                'id' => 'register-form',
                            ]); ?>

                            <!--昵称-->
                            <?= $form->field($register, 'user_name', 
                            [
                                'inputOptions' => ['placeholder'=>'昵称为2-18位,中英文、数字、下划线', 'class' => 'form-control'],
                                'enableAjaxValidation'=>true,
                                'enableClientValidation' => true,
                                'template' => '<div class="form-group user-nick">{input}</div>{error}',
                            ])->textInput() 
                            ?>

                            <!--密码-->
                            <?= $form->field($register, 'user_pwd', 
                            [
                                'inputOptions' => ['placeholder'=>'请输入密码', 'class' => 'form-control'],
                                'template' => '<div class="form-group">{input}</div>{error}',
                            ])->passwordInput()
                            ?>

                            <!--重复密码-->
                            <?= $form->field($register, 'user_qrpwd', 
                            [
                                'inputOptions' => ['placeholder'=>'请再次输入密码', 'class' => 'form-control'],
                                'template' => '<div class="form-group">{input}</div>{error}',
                            ])->passwordInput()
                            ?>
                                

                            <!--输入手机号-->
                            <?= $form->field($register, 'user_email_phone', 
                            [
                                'inputOptions' => ['placeholder'=>'请输入手机号或邮箱', 'class' => 'form-control'],
                                'enableAjaxValidation'=>true,
                                'enableClientValidation' => true,
                                'template' => '<div class="form-group">{input}</div>{error}',
                            ])->textInput()
                            ?>

                            <!--验证码-->
                            <?= $form->field($register, 'user_code', 
                            [
                                'inputOptions' => ['placeholder'=>'请输入验证码', 'class' => 'form-control form-control-phone fl'],
                                'template' => '<div class="form-group cf">{input}<span class="send-code fr"><button onclick="send_sms(this);" type="button" class="btn btn-micv5 btn-send">发送验证码</button></span></div>{error}',
                            ])->textInput()
                            ?>
                                
                            <div style="position: relative;" class="form-group"><input style="position: absolute; top: -2px;" type="checkbox" name="service_content" checked disabled>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="<?= Url::to(['index/servicecontent'])?>" target="_blank">用户注册条款点击查看详情</a></div>
                         
                        </div>
                    </div>
                    <p class="good-tips">已经有账号？<a href="#" data-toggle="modal" data-target="#loginModal" id="btnLogin">立即登录</a></p>
                    <div>
						<?= Html::submitButton('注册并登录', ['class' => 'btn btn-micv5 btn-block','id'=>'regloginbtn']) ?>  
						<?php ActiveForm::end(); ?>
                    </div>
                    <div id="register-tips" class="tips-error bg-danger">错误提示</div>
                </section>
            </div>
        </div>
    </div>
</div>
</div>
<script type="text/javascript" src="/static/js/common.js"></script>
<?php $this->endBody() ?>

</body>
</html>

<?php $this->endPage() ?>
<script>
    //退出
    $('#doOut').click(function(){
        $.post("<?= Url::to(['index/loginout'])?>",function(msg){
            
        });
    });

    
	/*菜单效果*/
	$(window).scroll(function(){
		var sc=$(window).scrollTop();
		var rwidth=$(window).width()
		if(sc>0){
			$("#goTopBtn").css("display","block");
			$("#goTopBtn").css("left",(rwidth-36)+"px")
		}else{
			$("#goTopBtn").css("display","none");
		}
	})
	$("#goTopBtn").click(function(){
		var sc=$(window).scrollTop();
		$('body,html').animate({scrollTop:0},1500);
	})

	//退出
	$("#loginout").click(function(){
		if(confirm('确定退出吗?')){
			location.href="<?= Url::to(['index/loginout'])?>";
		}else{
			return false;
		}
	})

	//获取验证码
    function send_sms(obj){
		var email_phone = $("#registerform-user_email_phone").val();
		if(!email_phone) return;

        var reg = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$|^([a-z0-9A-Z]+[-|\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\.)+[a-zA-Z]{2,}$/;
        if (!reg.test(email_phone)) return;

		$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['index/codes'])?>",
		   data: "email_phone="+email_phone,
		   success: function(msg){
			 if(msg == 1){
				RemainTime(obj);
				//alert('验证码已发送成功,请注意查收')		
			 }else if(msg == 2){
				//alert('发送邮件失败,请重新获取验证码')		
			 }else if(msg == 3){
				//alert('请输入正确的邮箱或手机号')		
			 }
		   }
		});
	}


	//获取密码按钮失效
	var iTime = 59;
	var Account;
	function RemainTime(obj){
        obj.disabled = true;
        
		var iSecond,sSecond="",sTime="";
		if (iTime >= 0){
			iSecond = parseInt(iTime%60);
			iMinute = parseInt(iTime/60)
			if (iSecond >= 0){
				if(iMinute>0){
					sSecond = iMinute + "分" + iSecond + "秒";
				}else{
					sSecond = iSecond + "秒后再次获取";
				}
			}
			sTime=sSecond;
			if(iTime==0){
				clearTimeout(Account);
				sTime='获取验证码';
				iTime = 59;
				obj.disabled = false;
			}else{
				Account = setTimeout(function(){RemainTime(obj);},1000);
				iTime=iTime-1;
			}
		}else{
			sTime='没有倒计时';
		}

		$(obj).text(sTime);
	}
	//修改密码获取验证码
	$("#fcode").click(function(){
		var email_phone = $("#forgetpwd").val();
		if(email_phone == ""){
			$('#pcode').html('请输入手机号或邮箱');
            return;
		}

        var reg = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$|^([a-z0-9A-Z]+[-|\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\.)+[a-zA-Z]{2,}$/;
        if (!reg.test(email_phone)) {
            $('#pcode').html('请输入正确的邮箱或手机号');
            return;
        }
		$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['index/getemailphone'])?>",
		   data: "email_phone="+email_phone,
		   success: function(msg){
			 if(msg == 1){
				$.ajax({
				   type: "POST",
				   url: "<?= Url::to(['index/codes'])?>",
				   data: "email_phone="+email_phone,
				   success: function(msg){
					 if(msg == 1){
						RemainTime(this);
						$('#pcode').html('验证码发送成功');	
					 }else if(msg == 2){
						$('#pcode').html('验证码发送失败');
					 }else if(msg == 3){
						$('#pcode').html('请输入正确的邮箱或手机号');		
					 }
				   }
				});
			 }else{
				alert('用户不存在')
			 }
		   }
		});
		
	})
	
	//检验密码
	$("#phone").blur(function(){
	    var phone = $("#forgetpwd").val();
	    var code = $(this).val()
	    $.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/validationcodes'])?>",
		   data: "phone="+phone+"&code="+code,
		   success: function(msg){
			 if(msg==1){
				document.getElementById('next').disabled = true;
				$('#pcode').html('验证码不能为空');
			 }else if(msg==2){
				 document.getElementById('next').disabled = false;
				 $('#pcode').html('');
			 }else{
				document.getElementById('next').disabled = true;
				$('#pcode').html('验证码错误');
			 }
		   }
		});
	})
		//修改新密码
	$("#newpwd").blur(function(){
		var newpwd = $(this).val();
		if(newpwd==""){
			$("#usernewpwd").html('请输入密码');
		}else if(newpwd.length<6 || newpwd.length>18){
			$("#usernewpwd").html('请输入6-18位密码');
		}else{
			$("#usernewpwd").html('');
		}
	})
	$("#rightnewpwd").blur(function(){
		var rightnewpwd = $(this).val();
		var newpwd = $("#newpwd").val();
		if(rightnewpwd==""){
			$("#qnewpwd").html('请输入确认密码');
		}else if(rightnewpwd!=newpwd){
			$("#qnewpwd").html('确认密码与密码不匹配');
		}else{
			$("#qnewpwd").html('');
			document.getElementById('save_pwd').disabled = false;
		}
		
	})
	$("#save_pwd").click(function(){
		var email_phone = $("#forgetpwd").val()
		var user_pwd = $("#rightnewpwd").val();
		$.ajax({
		   type: "POST",
		   url: "<?= Url::to(['center/savepwd'])?>",
		   data: "email_phone="+email_phone+"&user_pwd="+user_pwd,
		   success: function(msg){
			 if(msg == 1){
				alert('修改密码成功')
				location.href="<?= Url::to(['site/index'])?>";
			 }
		   }
		});
	})
</script>